#include "CAgent.h"
using namespace Content;
CAgent::CAgent()
{
  isMoving = false;
  curDir = DOWN;

  pEntity = createEntity();
  pEntity->createBoundingBox(0.7f,0.8f,1.5f);

}

CAgent::~CAgent()
{
  
}

void CAgent::init()
{
  pAgentMesh = createMeshFromXFile("agent.x");
  pAgentMesh->SetAnimation(1);
  pObject = pAgentMesh;
}
void CAgent::moveDir(int dir, float value)
{
  isMoving = true;
  pAgentMesh->SetAnimation(0);
  
  switch (dir)
  {
  case LEFT:
    if (curDir != LEFT)
    {
      curDir = LEFT;
      pObject->setYaw(PI/2.0f);
    }
    pEntity->moveVector(-value,0.0f,0.0f);
    break;

  case UPLEFT:
    if (curDir != UPLEFT)
    {
      curDir = UPLEFT;
      pObject->setYaw(PI/2.0f+PI/4.0f);
    }
    pEntity->moveVector(-value,0.0f,value);
    break;

  case UP:
    if (curDir != UP)
    {
      curDir = UP;
      pObject->setYaw(PI);
    }
    pEntity->moveVector(0.0f,0.0f,value);
    break;

  case UPRIGHT:
    if (curDir != UPRIGHT)
    {
      curDir = UPRIGHT;
      pObject->setYaw(PI+PI/4.0f);
    }
    pEntity->moveVector(value,0.0f,value);
    break;

  case RIGHT:
    if (curDir != RIGHT)
    {
      curDir = RIGHT;
      pObject->setYaw(PI+PI/2.0f);
    }
    pEntity->moveVector(value,0.0f,0.0f);
    break;

  case DOWNRIGHT:
    if (curDir != DOWNRIGHT)
    {
      curDir = DOWNRIGHT;
      pObject->setYaw(PI+PI/2.0f+PI/4.0F);
    }
    pEntity->moveVector(value,0.0f,-value);
    break;

  case DOWN:
    if (curDir != DOWN)
    {
      curDir = DOWN;
      pObject->setYaw(0.0f);
    }
    pEntity->moveVector(0.0f,0.0f,-value);
    break;

  case DOWNLEFT:
    if (curDir != DOWNLEFT)
    {
      curDir = DOWNLEFT;
      pObject->setYaw(PI/4.0F);
    }
    pEntity->moveVector(-value,0.0f,-value);
    break;
  default:
    break;

  }
}

void CAgent::update(float dT)
{
  pAgentMesh->moveVec(0.35f,0.0f,0.4f);
  if (!isMoving)
  {
    pAgentMesh->SetAnimation(1);
  }
  if (isMoving)
  {
    isMoving = false;
  }
}